package com.ruoyi.web.sso.controller;

import java.util.List;

import com.ruoyi.web.sso.domain.vo.MilepostList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.sso.domain.Milepost;
import com.ruoyi.web.sso.service.IMilepostService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 里程碑Controller
 * 
 * @author ruoyi
 * @date 2021-11-05
 */
@Controller
@RequestMapping("/sso/milepost")
@Api(tags = "里程碑")
public class MilepostController extends BaseController
{
    private String prefix = "sso/milepost";

    @Autowired
    private IMilepostService milepostService;

    @RequiresPermissions("sso:milepost:view")
    @GetMapping()
    @ApiOperation(value="查询列表页面",notes="查询列表页面")
    public String milepost()
    {
        return prefix + "/milepost";
    }

    /**
     * 查询里程碑列表
     */
    @RequiresPermissions("sso:milepost:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation(value="查询列表",notes="查询列表")
    public TableDataInfo list(Milepost milepost)
    {
        startPage();
        List<MilepostList> list = milepostService.selectMilepostList(milepost);
        return getDataTable(list);
    }

    /**
     * 导出里程碑列表
     */
    @RequiresPermissions("sso:milepost:export")
    @Log(title = "里程碑", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation(value="导出里程碑列表",notes="导出里程碑列表")
    public AjaxResult export(Milepost milepost)
    {
        List<MilepostList> list = milepostService.selectMilepostList(milepost);
        ExcelUtil<MilepostList> util = new ExcelUtil<MilepostList>(MilepostList.class);
        return util.exportExcel(list, "里程碑数据");
    }

    /**
     * 新增里程碑
     */
    @GetMapping("/add")
    @ApiOperation(value="新增里程碑页面",notes="新增里程碑页面")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存里程碑
     */
    @RequiresPermissions("sso:milepost:add")
    @Log(title = "里程碑", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value="新增保存里程碑",notes="新增保存里程碑")
    public AjaxResult addSave(Milepost milepost)
    {
        return toAjax(milepostService.insertMilepost(milepost));
    }

    /**
     * 修改里程碑
     */
    @GetMapping("/edit/{id}")
    @ApiOperation(value="修改里程碑页面",notes="修改里程碑页面")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        Milepost milepost = milepostService.selectMilepostById(id);
        mmap.put("milepost", milepost);
        return prefix + "/edit";
    }

    /**
     * 修改保存里程碑
     */
    @RequiresPermissions("sso:milepost:edit")
    @Log(title = "里程碑", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    @ApiOperation(value="修改保存里程碑",notes="修改保存里程碑")
    public AjaxResult editSave(Milepost milepost)
    {
        return toAjax(milepostService.updateMilepost(milepost));
    }

    /**
     * 删除里程碑
     */
    @RequiresPermissions("sso:milepost:remove")
    @Log(title = "里程碑", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    @ApiOperation(value="删除里程碑",notes="删除里程碑")
    public AjaxResult remove(String ids)
    {
        return toAjax(milepostService.deleteMilepostByIds(ids));
    }
}
